from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time

browser = webdriver.Chrome()

# 打开解锁页
browser.get("https://demo.mycodes.net/daima/suopingjiesuo/")
time.sleep(3)
patterview = browser.find_element_by_class_name("main-c")
print(patterview)
x = patterview.location.get('x')  # 九宫格的起始坐标x
y = patterview.location.get('y')  # 九宫格的起始坐标y

width = patterview.size.get('width')  # 九宫格的宽度
height = patterview.size.get('height')  # 九宫格的高度
#         print(x, y, width, height)
xstep = width / 3  # 宽度间隔
ystep = height / 3  # 高度间隔

# 九宫格第一个格子的坐标（即是九宫格的起始坐标）
xStartPoint = x + xstep
yStartPoint = y + ystep
print(xStartPoint)
print(yStartPoint)

action = ActionChains(browser)
action.move_to_element_with_offset(patterview, x, 0).perform()
time.sleep(0.5)
action.perform()
